package com.kws.tool.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kws.common.core.domain.R;
import com.kws.common.log.annotation.Log;
import com.kws.common.log.enums.BusinessType;
import com.kws.tool.dto.CreatePolicyMaintenanceRq;
import com.kws.tool.dto.QueryPolicyMaintenanceRq;
import com.kws.tool.dto.UpdatePolicyMaintenanceRq;
import com.kws.tool.entity.PolicyEntity;
import com.kws.tool.service.PolicyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <b>ToolPolicyController</b>
 *
 * @description: ToolPolicyController <br>
 * @date: 2024/11/20 18:15 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "政策维护模块")
@RestController
public class ToolPolicyController {
    private static final Logger logger = LoggerFactory.getLogger(ToolPolicyController.class);

    @Autowired
    private PolicyService policyService;

    @ApiOperation("分页查询政策维护列表")
    @PostMapping("/query/policyMaintenancePage")
    public R<Page<PolicyEntity>> queryPolicyMaintenancePage(@RequestBody QueryPolicyMaintenanceRq rq){
        Page<PolicyEntity> pageInfo = policyService.queryPolicyMaintenancePage(rq);
        return R.ok(pageInfo);
    }

    @ApiOperation("新增政策信息")
    @Log(title = "新增政策信息", businessType = BusinessType.INSERT)
    @PostMapping("/create/policyMaintenance")
    public R createPolicyMaintenance(@RequestBody CreatePolicyMaintenanceRq rq){
        boolean status = policyService.createPolicyMaintenance(rq);
        return R.ok(status);
    }

    @ApiOperation("根据政策ID查询政策详情")
    @GetMapping("/query/policyMaintenance/byId")
    public R<PolicyEntity> queryPolicyMaintenanceById(@RequestParam Long id){
        PolicyEntity info = policyService.queryPolicyMaintenanceById(id);
        return R.ok(info);
    }

    @ApiOperation("根据政策ID编辑政策信息")
    @Log(title = "修改政策信息", businessType = BusinessType.UPDATE)
    @PostMapping("/update/policyMaintenance")
    public R updatePolicyMaintenance(@RequestBody UpdatePolicyMaintenanceRq rq){
        boolean status = policyService.updatePolicyMaintenance(rq);
        return R.ok(status);
    }

    @ApiOperation("根据政策ID删除政策信息")
    @Log(title = "删除政策信息", businessType = BusinessType.DELETE)
    @GetMapping("/delete/policyMaintenance/byId")
    public R deletePolicyMaintenanceById(@RequestParam Long id){
        boolean status = policyService.deletePolicyMaintenanceById(id);
        return R.ok(status);
    }
}
